package cn.huangsm.advance.designmode.singlemode;

/**
 * 内部类实现方式
 * @author huang
 * @PACKAGE_NAME cn.huangsm.advance.designmode.singlemode
 * @PROJECT_NAME advance-code
 * @date 2019/1/24
 */
public class InnerType {
    /**
     * 内部类实现单例模式
     * 延迟加载，减少内存开销
     */
    private static class InnerHolder{
        private static InnerType innerType=new InnerType();
    }
    public static InnerType RealNumber(){
        return new InnerType();
    }
    /**
     * 私有化构造方法
     */
    private InnerType(){}
    public static InnerType getInstance(){
        return InnerHolder.innerType;
    }
    protected void method(){
        System.out.println("内部类方式实现");
    }

    public static void main(String[] args) {
        InnerType innerType = InnerType.RealNumber();
        System.out.println(innerType);
        InnerType.getInstance().method();

    }
}
